Skip to content

fix: "already activated" message but shell is not active#57

Open
kenttonino wants to merge 4 commits into
python-poetry:mainfrom
kenttonino:fix/should-return-false-if-poetry-active-but-not-virtual-env
Open

fix: "already activated" message but shell is not active#57
kenttonino wants to merge 4 commits into
python-poetry:mainfrom
kenttonino:fix/should-return-false-if-poetry-active-but-not-virtual-env

Conversation

@kenttonino
Copy link
Copy Markdown

@kenttonino kenttonino commented Apr 9, 2026

Summary

  • Fixes Poetry shell command does not start shell #21
  • If we have a newly created shell, then deactivate, then activate the shell again, it will only show a message that Virtual environment already activated, but its not activated.
    • The problem is that we only check if the POETRY_ACTIVE is set, but not the VIRTUAL_ENV.


Changes

  • command.py:
    • If the POETRY_ACTIVE is set but not the VIRTUAL_ENV, pop the POETRY_ACTIVE.


Test Plan

Test 1

  • Create shell.
  • Deactivate the shell.
  • Activate again the shell.
    • It should activate the shell.

Test 2

  • Activate the shell.
  • Then, activate again.
    • It should show Virtual environment already activated.

@kenttonino kenttonino changed the title [ fix ] Should Return False if POETRY_ACTIVE is true but not VIRTUAL_ENV [ fix ] Already Activated But Shell Is Not Active Apr 9, 2026
@kenttonino kenttonino changed the title [ fix ] Already Activated But Shell Is Not Active [ fix ] Already Activated But Shell Is Not Active (in progress) Apr 9, 2026
@kenttonino kenttonino marked this pull request as ready for review April 9, 2026 17:09
@kenttonino kenttonino changed the title [ fix ] Already Activated But Shell Is Not Active (in progress) [ fix ] Already Activated But Shell Is Not Active Apr 9, 2026
@kenttonino kenttonino changed the title [ fix ] Already Activated But Shell Is Not Active [ fix ] Already Activated Message But Shell Is Not Active Apr 9, 2026
@kenttonino kenttonino changed the title [ fix ] Already Activated Message But Shell Is Not Active fix: "already activated" message but shell is not active Apr 10, 2026
Copy link
Copy Markdown

@StantonMatt StantonMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked this locally because the issue thread is a little mixed between “use exit rather than deactivate” and the stale environment state described in the PR.

The behavior change looks valid to me. With POETRY_ACTIVE=1 and no VIRTUAL_ENV, a focused regression probe fails on current main because Shell.activate() is not called, then passes on this branch. The existing already-active behavior is still preserved when both POETRY_ACTIVE and VIRTUAL_ENV point at the active env.

Local checks I ran on this branch:

  • python -m pytest -q tests/test_shell_command.py
  • python -m pytest -q
  • python -m ruff check src/poetry_plugin_shell/command.py tests/test_shell_command.py
  • python -m mypy src/poetry_plugin_shell/command.py tests/test_shell_command.py

I also checked the visible PR jobs individually: Ubuntu/macOS/Windows for Python 3.10-3.14 and pre-commit are all green.

One small thing I would consider before merge: the test change in this PR preserves the already-active case, but it does not directly assert the new stale POETRY_ACTIVE without VIRTUAL_ENV path. The scratch regression above passed on this branch, so this is not a behavior blocker, but adding that as a committed test would make the fix easier to protect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Poetry shell command does not start shell

2 participants